<template>
	<view>
		<view class="box" v-if="goods.length>0">
			<view class="info" v-for="(item,index) in goods" :key="index">
				<image :src="item.url" class="info_left"></image>
				<view class="info_right">
					<view class="title_box">
						<view class="title">{{item.goods_title}}</view>
						<!-- <view class="status">{{pay_status[info.pay_status]}}</view> -->
					</view>
					<view class="time_box">
						<!-- <view class="tag">报名截止时间</view> -->
						<view class="time">{{item.spec_name}}</view>
						<!-- <view class="class_hour">共22课节</view> -->
					</view>
					<view class="teacher">X{{item.goods_num}}</view>
				</view>
			</view>
		</view>
		<!-- 申请原因 -->
		<view class="reason">
			<view class="item_left">选择售后商品</view>
			<view class="item_right" @click="openPopup "><text>{{familyname}}</text>
				<image src="@/static/jt1.png"></image>
			</view>
		</view>
		<!-- 退款额度： -->
		<!-- <view class="refund">
			<view class="item_left">退款额度：</view>
			<view class="item_right">3688<text class="small">积分</text>+<text class="small">￥</text>10
				</image>
			</view>
		</view> -->

		<!-- 补充描述和凭证 -->
		<view class="description">
			<view class="title">
				<view class="title_left">申请原因</view>
				<!-- <view class="title_right">您还可以输入{{comInput}}字</view> -->
			</view>
			<textarea class="textarea" auto-height v-model="reason" :maxlength="100" placeholder="选填，请您补充描述，更好的处理问题"
				placeholder-class="placInput"></textarea>
			<view class="addimg" v-if="imglist.length==0" @click="uploadimg()">
				<image src="../../static/xj.png"></image>
				<view>添加图片</view>
			</view>
			<view class="imgbox" v-else>
				<view class="imglist" v-for="(item,index) in imglist" :key="index">
					<image :src="item" style="border-radius: 16rpx;"></image>
					<image class="closen" src="../../static/off.png" @click="spliceimg(index)"></image>
				</view>
				<view class="imglist" @click="uploadimg()" style="border:2rpx dashed #999999,width:33%" v-if="imglist.length<6">
					<image style="width: 66rpx;height: 60rpx; margin: 50rpx 0 10rpx 0;" src="../../static/xj.png">
					</image>
					<view>添加图片</view>
				</view>
			</view>
		</view>
		<view class="refoundbut" @click="sumbit()">
			提交
		</view>


		<!-- 弹框 -->
		<uni-popup ref="popup">
			<view class="popup_box">
				<view class="title_box">
					<text class="zw"></text>
					<text>退款商品</text>
					<image src="../../static/off.png" @click="offHxm"></image>
				</view>
				<view style="width: 100%;height: 100%;">
					<view class="popup_content" v-if="familylist">
						<view class="content_item" v-for="(item,index) in familylist" :key="item.goods_id" 
						@click="popupChange(item,index)">
							<view class="right">
								<image :src="item.url"></image>
							</view>
							<view class="left">
								<view class="name">{{item.goods_title}}</view>
								<view class="tip">{{item.spec_name}}</view>
								<view class="numbox">X{{item.goods_num}}</view>
							</view>
							<view class="yuan">
								<image v-if="!item.flag" src="../../static/yuan.png"></image>
								<image v-else src="../../static/gou.png"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="btn" @click="verify">
					确定
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 可输入最大值
				maxInput: 170,
				input: "",
				imglist: [],
				familylist: [],
				changeID: null,
				reason: "",
				familyname:'请选择',
				id:'',
				info:{},
				goodslist:[],
				goods:[],
				choose_all:'',//是否全选
				pay_status:['未支付','待上课','已完结','待评价','已完成','已退款','已取消'],//支付状态0未支付1已支付/待核销3已核销/待评价4已评价/已完成5已退款6已取消
			};
		},
		onLoad(option) {
			this.id = option.id
			this.getinfo(option.id)
			// this.getfamfily()
		},
		methods: {
			async getinfo(id){
				await this.$http({
					url:'/api/Wechat/orderDetail',
					data:{
						orderid:id
					}
				}).then(res=>{
					this.info = res.data
					this.familylist = this.info.goods
					this.familylist.forEach(item=>{
						item.flag = false
					})
					console.log(this.info.goods)
				})
			},
			// getfamfily(){
			// 	this.$http({
			// 		url:'/api/course/family_list'
			// 	}).then(res=>{
			// 		this.familylist = res.data
			// 	})
			// },
			//添加图片
			uploadimg() {
				this.$upload(1).then(res => {
					this.imglist.push(...res)
					console.log(this.imglist, 'this.imglist', res) //item.file.full_url
				})
			},
			//删除图片
			spliceimg(index) {
				this.imglist.splice(index, 1)
			},
			sumbit(){
				if(this.goodslist.length==0){
					uni.showToast({
						title:'请选择售后商品',
						icon:'none'
					})
					return
				}
				this.$http({
					url:'/api/Wxpay/goods_refund',
					data:{
						goods_id:this.goodslist,
						orderid:this.id,
						desc:this.reason,
						choose_all:this.choose_all==true?1:0,//是否全选 0否 1是
						picarr:this.imglist.join(','),
					}
				}).then(res=>{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
					uni.navigateTo({
						url:'/pageshop/orderlist/orderlist'
					})
				})
			},
			// 打开弹窗
			openPopup() {
				this.$refs.popup.open("bottom")
			},
			offHxm(){
				this.$refs.popup.close()
			},
			// 弹框内容选择事件
			popupChange(item,index) {
				this.familylist[index].flag = !this.familylist[index].flag
				this.familylist = [...[],...this.familylist]
				this.choose_all = this.familylist.every(item => item.flag==true)
				console.log(this.info.goods,this.familylist,this.familylist[index].flag,this.choose_all)
				// console.log(e.detail.value);
				// this.changeID = e.detail.value
			},
			// 弹框确定
			verify() {
				this.goods = this.familylist.filter(item => item.flag==true)
				this.familylist.forEach(item=>{
					if(item.flag==true){
						this.goodslist.push(item.goods_id)
					}
				})
				// if (!this.changeID) return
				// this.familyname = this.info.class_time[0].family.find(item => item.goods_id == this.changeID).name
				this.$refs.popup.close()
			},
			dateFormat: function(value) {
			                var date = new Date(value*1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
			                var year = date.getFullYear();
			                var month = ("0" + (date.getMonth() + 1)).slice(-2);
			                var sdate = ("0" + date.getDate()).slice(-2);
			                var hour = ("0" + date.getHours()).slice(-2);
			                var minute = ("0" + date.getMinutes()).slice(-2);
			                var second = ("0" + date.getSeconds()).slice(-2);
			                // 拼接
			                var result = year + "年" + month + "月" + sdate + "日 " + hour + ":" + minute //+ ":" + second;
			                // 返回
			                return result;
			            },
		},
		computed: {
			comInput() {
				return this.maxInput - this.input.length
			}
		}
	}
</script>
<style>
	.placInput {
		font-size: 32rpx;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #888888;
	}
</style>
<style lang="scss" scoped>
	// 
	.box {
		width: 750rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 36rpx 30rpx 0 30rpx;
		box-sizing: border-box;
		margin: 20rpx auto 24rpx auto;

		.info {
			display: flex;
			justify-content: space-between;
			gap: 0 26rpx;
			padding-bottom: 30rpx;

			.info_left {
				width: 160rpx;
				height: 160rpx;
				background: #FFFFFF;
				border-radius: 6rpx;
				flex-shrink: 0;
			}

			.info_right {
				width: 100%;
				display: flex;
				flex-direction: column;

				.title_box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 30rpx;

					.title {
						font-size: 36rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #222222;
						line-height: 1em;
					}

					.status {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #FF8A9B;
					}
				}

				.time_box {
					display: flex;
					align-items: center;
					margin-bottom: 20rpx;
					justify-content: space-between;
				
					.tag {
						padding: 6rpx 6rpx 4rpx 6rpx;
						background: linear-gradient(180deg, #FCBB8C 0%, #FF8158 100%);
						font-size: 28rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #FFFFFF;
						line-height: 1em;
						border-radius: 4rpx 8rpx 8rpx 8rpx;
						// margin-right: 18rpx;
					}
				
					.time {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #555555;
						line-height: 1em;
						// margin-right: 20rpx;
					}
				
					.class_hour {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #555555;
						line-height: 1em;
					}
				}

				.teacher {
					font-size: 28rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #555555;
					line-height: 1em;
				}

			}
		}
	}

	// 退款原因
	.reason {
		width: 750rpx;
		height: 98rpx;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 28rpx;
		box-sizing: border-box;

		.item_left {
			font-size: 32rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #222222;
		}

		.item_right {
			font-size: 32rpx;
			font-family: SourceHanSansCN-Regular-, SourceHanSansCN-Regular;
			font-weight: normal;
			color: #888888;
			display: flex;
			align-items: center;
			gap: 0 24rpx;

			image {
				width: 8rpx;
				height: 16rpx;
			}
		}
	}

	// 退款额度
	.refund {
		width: 750rpx;
		height: 98rpx;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		display: flex;
		align-items: center;
		padding: 0 28rpx;
		box-sizing: border-box;
		margin-top: 24rpx;

		.item_left {
			font-size: 32rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #222222;
		}

		.item_right {
			font-size: 32rpx;
			font-family: Source Han Sans CN-Medium, Source Han Sans CN;
			font-weight: 500;
			color: #FF6178;
			display: flex;
			align-items: center;

			.small {
				font-size: 24rpx;
			}

		}
	}

	// 补充描述和凭证
	.description {
		width: 750rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin-top: 26rpx;
		padding: 30rpx 30rpx 24rpx 30rpx;
		box-sizing: border-box;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 40rpx;

			.title_left {
				font-size: 32rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #222222;
				line-height: 1em;
			}

			.title_right {
				font-size: 32rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #555555;
				line-height: 1em;
			}
		}

		.textarea {
			width: 100%;
			min-height: 200rpx;
			margin-bottom: 30rpx;
		}
		.addimg {
			height: 236rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			text-align: center;
			font-size: 28rpx;
			font-family: SourceHanSansCN-Medium-, SourceHanSansCN-Medium;
			font-weight: normal;
			color: #999999;
			margin-top: 20rpx;
			border: 2rpx dashed #999999;
		
			image {
				width: 66rpx;
				height: 60rpx;
				margin-top: 50rpx;
				margin-bottom: 10rpx;
			}
		}
		
		.imgbox {
			display: flex;
			flex-wrap: wrap;
			margin-top: 20rpx;
		
			.imglist {
				width: 33.3%;
				text-align: center;
				position: relative;
		
				image {
					width: 208rpx;
					height: 208rpx;
				}
		
				.closen {
					width: 40rpx;
					height: 40rpx;
					position: absolute;
					right: 10rpx;
					top: 0;
				}
			}
		}

		.image_box {
			width: 100%;
			min-height: 157rpx;
			display: flex;
			flex-wrap: wrap;
			gap: 18rpx;


			image {
				width: 157rpx;
				height: 157rpx;
			}

			.upload_image {
				width: 157rpx;
				height: 157rpx;
				background: #FFFFFF;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				border: 2rpx dashed #DBDBDB;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				gap: 20rpx 0;
				font-size: 24rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #999999;
				line-height: 1em;

				image {
					width: 49rpx;
					height: 45rpx;
				}
			}
		}
	}

	// 弹框
	.popup_box {
		width: 750rpx;
		height: 694rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		display: flex;
		flex-direction: column;

		.title_box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			height: 128rpx;
			padding: 0 32rpx;
			box-sizing: border-box;
			flex-shrink: 0;
			border-bottom: 1rpx solid #DBDBDB;

			.zw {
				display: block;
				width: 40rpx;
				height: 40rpx;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.popup_content {
			width: 100%;
			height: 100%;
			padding: 50rpx 30rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.content_item {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					width: 480rpx;
					font-size: 32rpx;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					font-weight: 400;
					color: #333333;
					.name{
						font-size: 32rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #222222;
					}
					.tip{
						font-size: 26rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #666666;
						margin: 10rpx 0;
					}
					.numbox{
						font-size: 26rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #666666;
					}
				}

				.right {
					width: 120rpx;
					font-size: 32rpx;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					font-weight: 400;
					color: #333333;
					text-align: center;
					image{
						width: 90rpx;
						height: 90rpx;
						border-radius: 20rpx;
					}
				}
				.yuan{
					width: 90rpx;
					text-align: center;
					image{
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
		}

		.btn {
			width: 690rpx;
			height: 84rpx;
			background: #FF8A9B;
			border-radius: 83rpx 83rpx 83rpx 83rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 24rpx auto;
			flex-shrink: 0;
			font-size: 36rpx;
			font-family: Source Han Sans CN-Medium, Source Han Sans CN;
			font-weight: 500;
			color: #FFFFFF;
		}
	}
	.refoundbut{
		width: 690rpx;
		height: 84rpx;
		background: #FF8A9B;
		border-radius: 83rpx;
		margin: 50rpx auto;
		font-size: 36rpx;
		font-family: Source Han Sans CN-Medium, Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		line-height: 84rpx;
	}
</style>
